﻿using GameFramework.Event;
using System;
using TowerDefence_Zombie.Data;

namespace TowerDefence_Zombie
{
    public class GuideCondition_UnlockPlace : GuideCondition_Base
    {
        private int _targetPlaceId;

        public GuideCondition_UnlockPlace(DRGuideCondition conditionInfo, Action conitionCompleteClick)
            : base(conditionInfo, conitionCompleteClick)
        {
            _targetPlaceId = conditionInfo.ConditionParams_Int;
        }

        public override void StartCondition()
        {
            base.StartCondition();
            GameEntry.Event.Subscribe(UnlockPlacementEventArgs.EventId, OnPlacementUnlock);
            if (GameEntry.Data.GetData<DataPlacement>().GetPlacementAreaUnlockState(_targetPlaceId))
            {
                IsCompleteFlag = true;
            }
        }

        private void OnPlacementUnlock(object sender, GameEventArgs e)
        {
            UnlockPlacementEventArgs ne = (UnlockPlacementEventArgs)e;
            if (ne == null)
                return;

            if (ne.AreaId == _targetPlaceId)
            {
                IsCompleteFlag = true;
            }
        }

        public override void Dispose()
        {
            GameEntry.Event.Unsubscribe(UnlockPlacementEventArgs.EventId, OnPlacementUnlock);
            base.Dispose();
        }
    }
}
